package com.cictec.middleware.core.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cictec.middleware.commons.utils.PMSUtils;
import com.cictec.middleware.core.entity.WarnMsg;
import com.cictec.middleware.core.mapper.WarnMsgMapper;

import tk.mybatis.mapper.entity.Example;

@Service
public class WarnMsgService {

	private static Logger logger = LoggerFactory.getLogger(WarnMsgService.class);
	
	@Autowired
	private WarnMsgMapper warnMsgMapper;
	

	/**
	 * 保存、修改报警信息
	 * @param warnMsg
	 */
	public void saveWarn(WarnMsg warnMsg) {

		if(PMSUtils.isEmpty(warnMsg.getWarnUuid())){
			warnMsg.setWarnUuid(PMSUtils.getUUID());
			
			warnMsgMapper.insertSelective(warnMsg);
			logger.debug("【WarnMsgService】【新增】报警信息 devUuid:{} 类型:{}", warnMsg.getWarnDevUuid(), warnMsg.getWarnType());
		}else{
			warnMsgMapper.updateByPrimaryKeySelective(warnMsg);
			logger.debug("【WarnMsgService】【修改】报警信息 devUuid:{} 类型:{}", warnMsg.getWarnDevUuid(), warnMsg.getWarnType());
		}
	}
	
	/**
	 * 删除指定日期、类型报警
	 * @param date
	 * @param warnType
	 */
	public void deleteWarn(String date, String warnType){
		Example example = new Example(WarnMsg.class);
		example.createCriteria()
			.andEqualTo("warnType", warnType)
			.andLike("warnStartTime", date+"%");
		warnMsgMapper.deleteByExample(example);
	}
	
	/**
	 * 删除指定日期、车辆、类型
	 * @param date
	 * @param warnType
	 */
	public void deleteWarn(String date, String warnType, String busUuid){
		Example example = new Example(WarnMsg.class);
		example.createCriteria()
		.andEqualTo("warnBusUuid", busUuid)
		.andEqualTo("warnType", warnType)
		.andLike("warnStartTime", date+"%");
		warnMsgMapper.deleteByExample(example);
	}

	
	public WarnMsg getWarnMsgByDev(String devUuid, String type) {
		return null;
	}
}
